﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls.DataVisualization.Charting;
using System.Collections.Generic;
using SilverlightApp.data;
using System.Collections;
using System.Collections.ObjectModel;
using SilverlightApp.Common;
using System.Windows.Threading;

namespace SilverlightApp.Web
{
    public class IlluminationChartBuilder2 : ColumnChartBuilderBase
    {
        protected override void AfterSeriesBuild(ColumnSeries series)
        {
            series.Width = 100;
        }

        protected override void AfterChartBuild(Chart chart)
        {
            chart.Height = 230;
            //warningDispatcherTimer.Interval
        }

        protected override void AfterLinearAxisBuild(LinearAxis la)
        {
            la.Interval = 20;
        }

        public override void BuildChart(Panel panel, MyObservableCollection<PairInfo> ds)
        {
            ColumnChartBuildContext bc = new ColumnChartBuildContext();
            bc.ChartTitle = "光照监控";
            bc.ColumnColor = Color.FromArgb(255, 0, 255, 0);
            bc.DataSource = ds;
            bc.AfterPropertyChangedEnventHandler = (chart, self) =>
            {
                if (self != null && self.Count > 0)
                {
                    var valueAxis = chart.Axes[0] as LinearAxis;
                    double value = Math.Round(self[0].Value, 2);
                    if (self != null && self.Count > 0)
                    {
                        //series.Title = value + " lx";
                        chart.Title = string.Format("光照监控" + Environment.NewLine + "({0}lx)", value);
                    }
                    valueAxis.Interval = (int)(((valueAxis.Maximum.Value - valueAxis.Minimum.Value) / 6 + 10) / 10) * 10;
                    if (valueAxis.Maximum.Value < value)
                    {
                        valueAxis.Maximum = value + 10;
                    }
                }                   
            };
            BuildChartCore(panel, bc);
            return;
        }
    }
}
